package com.itheima.tcp3;

import java.io.DataOutputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;

public class Client1 {

    public static void main(String[] args) throws Exception {

        //简单的TCP通信多发多收：客户端开发

        System.out.println("==========客户端启动==========");

        //1.创建Socket管道对象，请求与服务端的Socket建立连接
        Socket socket = new Socket("192.168.0.6", 9999);

        //2.从Socket管道中得到一个字节输出流
        OutputStream os = socket.getOutputStream();

        //3.使用特殊的字节输出流，写数据
        DataOutputStream dos = new DataOutputStream(os);

        Scanner sc = new Scanner(System.in);
        while (true) {
            System.out.println("请输入要发送的内容：");
            String msg = sc.nextLine();

            if ("exit".equals(msg)) {
                System.out.println("==========客户端退出==========");
                dos.close();
                socket.close();
                break;
            }
            dos.writeUTF(msg);
            dos.flush();

        }

    }
}
